package com.gitee.wsl.time.local

import kotlinx.serialization.Serializable
@Serializable
data class TimezoneNames(val timeZones: List<Timezone>) {
    val namesToOffsetsList by lazy { timeZones.groupBy { it.abbr } }
    val namesToOffsets by lazy { namesToOffsetsList.map { it.key to it.value.first().offset }.toMap() }
    constructor(vararg tz: Timezone) : this(tz.toList())

    operator fun plus(other: TimezoneNames): TimezoneNames = TimezoneNames(this.timeZones + other.timeZones)
    operator fun get(name: String): Timezone? = namesToOffsetsList[name.uppercase().trim()]?.first()

    /** Some abbreviations collides, so we can get a list of Timezones based on abbreviation */
    fun getAll(name: String): List<Timezone> = namesToOffsetsList[name.uppercase().trim()] ?: emptyList()

    companion object {
        @Suppress("MayBeConstant", "unused")
        private const val serialVersionUID = 1L

        val DEFAULT = TimezoneNames(
            Timezone.PDT,
            Timezone.PST,
            Timezone.GMT,
            Timezone.UTC,
            Timezone.CET,
            Timezone.CEST,
        )

        val ExtendedTimezoneNames: TimezoneNames by lazy {
            TimezoneNames(
                Timezone.ACDT,
                Timezone.ACST,
                Timezone.ACT,
                Timezone.ACWST,
                Timezone.ADT,
                Timezone.AEDT,
                Timezone.AEST,
                Timezone.AFT,
                Timezone.AKDT,
                Timezone.AKST,
                Timezone.ALMT,
                Timezone.AMST,
                Timezone.AMT_ARMENIA,
                Timezone.AMT_BRAZIL,
                Timezone.ANAT,
                Timezone.AQTT,
                Timezone.ART,
                Timezone.AST_ARABIA,
                Timezone.AST_ATLANTIC,
                Timezone.AWST,
                Timezone.AZOST,
                Timezone.AZOT,
                Timezone.AZT,
                Timezone.BDT,
                Timezone.BIOT,
                Timezone.BIT,
                Timezone.BOT,
                Timezone.BRST,
                Timezone.BRT,
                Timezone.BST_BOUGAINVILLE,
                Timezone.BST_BANGLADESH,
                Timezone.BST_BRITISH,
                Timezone.BTT,
                Timezone.CAT,
                Timezone.CCT,
                Timezone.CDT_AMERICA,
                Timezone.CDT_CUBA,
                Timezone.CEST,
                Timezone.CET,
                Timezone.CHADT,
                Timezone.CHAST,
                Timezone.CHOT,
                Timezone.CHOST,
                Timezone.CHST,
                Timezone.CHUT,
                Timezone.CIST,
                Timezone.CIT,
                Timezone.CKT,
                Timezone.CLST,
                Timezone.CLT,
                Timezone.COST,
                Timezone.COT,
                Timezone.CST_AMERICA,
                Timezone.CST_CHINA,
                Timezone.CST_CUBA,
                Timezone.CT,
                Timezone.CVT,
                Timezone.CWST,
                Timezone.CXT,
                Timezone.DAVT,
                Timezone.DDUT,
                Timezone.DFT,
                Timezone.EASST,
                Timezone.EAST,
                Timezone.EAT,
                Timezone.ECT_CARIBBEAN,
                Timezone.ECT_ECUADOR,
                Timezone.EDT,
                Timezone.EEST,
                Timezone.EET,
                Timezone.EGST,
                Timezone.EGT,
                Timezone.EIT,
                Timezone.EST,
                Timezone.FET,
                Timezone.FJT,
                Timezone.FKST,
                Timezone.FKT,
                Timezone.FNT,
                Timezone.GALT,
                Timezone.GAMT,
                Timezone.GET,
                Timezone.GFT,
                Timezone.GILT,
                Timezone.GIT,
                Timezone.GMT,
                Timezone.GST_GEORGIA,
                Timezone.GST_GULF,
                Timezone.GYT,
                Timezone.HDT,
                Timezone.HAEC,
                Timezone.HST,
                Timezone.HKT,
                Timezone.HMT,
                Timezone.HOVST,
                Timezone.HOVT,
                Timezone.ICT,
                Timezone.IDLW,
                Timezone.IDT,
                Timezone.IOT,
                Timezone.IRDT,
                Timezone.IRKT,
                Timezone.IRST,
                Timezone.IST_INDIA,
                Timezone.IST_IRISH,
                Timezone.IST_ISRAEL,
                Timezone.JST,
                Timezone.KALT,
                Timezone.KGT,
                Timezone.KOST,
                Timezone.KRAT,
                Timezone.KST,
                Timezone.LHST_STD,
                Timezone.LHST_SUMMER,
                Timezone.LINT,
                Timezone.MAGT,
                Timezone.MART,
                Timezone.MAWT,
                Timezone.MDT,
                Timezone.MET,
                Timezone.MEST,
                Timezone.MHT,
                Timezone.MIST,
                Timezone.MIT,
                Timezone.MMT,
                Timezone.MSK,
                Timezone.MST_AMERICA,
                Timezone.MST_MALAYSIA,
                Timezone.MUT,
                Timezone.MVT,
                Timezone.MYT,
                Timezone.NCT,
                Timezone.NDT,
                Timezone.NFT,
                Timezone.NOVT,
                Timezone.NPT,
                Timezone.NST,
                Timezone.NT,
                Timezone.NUT,
                Timezone.NZDT,
                Timezone.NZST,
                Timezone.OMST,
                Timezone.ORAT,
                Timezone.PDT,
                Timezone.PET,
                Timezone.PETT,
                Timezone.PGT,
                Timezone.PHOT,
                Timezone.PHT,
                Timezone.PKT,
                Timezone.PMDT,
                Timezone.PMST,
                Timezone.PONT,
                Timezone.PST,
                Timezone.PST,
                Timezone.PYST,
                Timezone.PYT,
                Timezone.RET,
                Timezone.ROTT,
                Timezone.SAKT,
                Timezone.SAMT,
                Timezone.SAST,
                Timezone.SBT,
                Timezone.SCT,
                Timezone.SDT,
                Timezone.SGT,
                Timezone.SLST,
                Timezone.SRET,
                Timezone.SRT,
                Timezone.SST_SAMOA,
                Timezone.SST_SINGAPORE,
                Timezone.SYOT,
                Timezone.TAHT,
                Timezone.THA,
                Timezone.TFT,
                Timezone.TJT,
                Timezone.TKT,
                Timezone.TLT,
                Timezone.TMT,
                Timezone.TRT,
                Timezone.TOT,
                Timezone.TVT,
                Timezone.ULAST,
                Timezone.ULAT,
                Timezone.UTC,
                Timezone.UYST,
                Timezone.UYT,
                Timezone.UZT,
                Timezone.VET,
                Timezone.VLAT,
                Timezone.VOLT,
                Timezone.VOST,
                Timezone.VUT,
                Timezone.WAKT,
                Timezone.WAST,
                Timezone.WAT,
                Timezone.WEST,
                Timezone.WET,
                Timezone.WIT,
                Timezone.WST,
                Timezone.YAKT,
                Timezone.YEKT,
            )
        }
    }
}